// 兼容IE
// 去掉以下两行，改用在 babel.config.js 中配置 "@babel/plugin-transform-runtime"插件
// import 'core-js/stable'
// import 'regenerator-runtime/runtime'

// 安装依赖
import dependencies from './core/init-dependencies'

import ZhCmp, { ZPageCard } from '@zh/components-ant'

import routeCreator, { router } from './router'
import storeCreator, { store } from './store'
import themes from './themes'

import httpConfig from './http'

// 模块、组件、插件等初始化完成，自定义业务逻辑处理
import bootstrap from '@/bootstrap'

// 启动 new Vue()
import starter, { globalComponents, globalPlugins } from './core/starter'

import UserInfoHeader from './components/UserInfoHeader.vue'

import MenuHeader from './components/MenuHeader'

import AlwaysMultiTab from './components/multi-tab/AlwaysMultiTab.vue'
import DefaultMultiTab from './components/multi-tab/DefaultMultiTab.vue'
import AlwaysMultiTabMinix from './components/multi-tab/AlwaysMultiTabMinix'
import DefaultMultiTabMinix from './components/multi-tab/DefaultMultiTabMinix'
import ThemesSetting from './components/ThemesSetting.vue'

import { globalComponent } from './globalComponent.js'

import MicroApp from './micro-app'

const install = (Vue) => {
  if (install.installed) {
    return
  }

  // 创建 Vuex 实例
  Vue.use(storeCreator)

  // 创建 VueRouter 实例
  Vue.use(routeCreator)

  // 初始化 Http 配置
  Vue.use(httpConfig, router, store)

  Vue.use(dependencies)

  // 全局注册组件库
  Vue.use(ZhCmp, router, store)

  // 设置全局默认组件
  setGlobalDefaultComponents(Vue)

  // 设置微应用
  Vue.use(MicroApp)

  // 模块、组件、插件等初始化完成，自定义业务逻辑处理
  Vue.use(bootstrap)

  Vue.prototype.$microApp = new MicroApp(Vue)

  Vue.use(themes, {})

  // 启动 new Vue()
  Vue.use(starter)

  install.installed = true
}

/**
 * 设置全局默认组件
 */
function setGlobalDefaultComponents (Vue) {
  // 全局默认登录用户展示组件
  globalComponent.setUserInfoHeader(UserInfoHeader)

  // 全局默认PageCard组件
  globalComponent.setPageCard(ZPageCard)

  // 全局默认菜单头部组件
  globalComponent.setMenuHeader(MenuHeader)

  // 全局默认多标签
  globalComponent.setDefaultMultiTab(DefaultMultiTab)
  globalComponent.setAlwaysMultiTab(AlwaysMultiTab)

  globalComponent.setThemesSetting(ThemesSetting)
}

install.globalComponent = globalComponent
install.globalPlugins = globalPlugins

/**
 * 对外暴露自定义菜单图标配置接口
 */
export { setMenuIconsConfig } from './views/menu/menuIcon'

export {
  router,
  store,
  MicroApp,
  globalComponent,
  globalPlugins,
  AlwaysMultiTabMinix,
  DefaultMultiTabMinix
}

export default {
  install
}
